/*
 * Copyright (C) 2012  Romain DUBOIS
 * 
 * This file is part of NeMoS - Network and Modular Software
 * 
 * NeMoS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * NeMoS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with NeMoS.  If not, see <http://www.gnu.org/licenses/>.
 */
package nemos.launch;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import nemos.launch.progress.IProgressDisplay;

/**
 * ProgressDisplayTestImpl : The progress display test implementation.
 * 
 * @author Romain DUBOIS
 */
public class ProgressDisplayTestImpl implements IProgressDisplay {

    /** The received progresses */
    private final LinkedList<Integer> mProgressValues;
    /** The received labels (sorted with their current progress) */
    private final Map<Integer, List<String>> mLabels;

    /**
     * Constructor
     */
    public ProgressDisplayTestImpl() {
        super();
        mProgressValues = new LinkedList<Integer>();
        mLabels = new HashMap<Integer, List<String>>();
    }

    /**
     * {@inheritDoc}
     * 
     * @see nemos.launch.progress.IProgressDisplay#setProgressValue(int)
     */
    @Override
    public void setProgressValue(final int pProgressValue) {
        mProgressValues.add(Integer.valueOf(pProgressValue));
    }

    /**
     * {@inheritDoc}
     * 
     * @see nemos.launch.progress.IProgressDisplay#setLabel(java.lang.String)
     */
    @Override
    public void setLabel(final String pLabel) {
        Integer lLastProgress = Integer.valueOf(0);
        if (!mProgressValues.isEmpty()) {
            lLastProgress = mProgressValues.getLast();
        }
        List<String> lLabels = mLabels.get(lLastProgress);
        if (lLabels == null) {
            lLabels = new ArrayList<String>();
            mLabels.put(lLastProgress, lLabels);
        }

        lLabels.add(pLabel);
    }

    /**
     * Get the received labels grouped by the current progress value and sorted
     * by reception order.
     * 
     * @return the labels
     */
    public Map<Integer, List<String>> getLabels() {
        return mLabels;
    }

    /**
     * Get the received progress values sorted in the reception order.
     * 
     * @return The progresses
     */
    public List<Integer> getProgressValues() {
        return mProgressValues;
    }
}
